/**
 * 项目名称:
 *
 * 定义一个学生类，包含学号、姓名、性别、年龄等信息，完成如下功能：
 * 	A、将5个学生对象添加到ArrayList集合对象中
 * 	B、判断名叫张三的学生是否存在于该集合中
 * 	C、统计年龄小于18岁的人数
 * 	D、打印出所有学生的信息
 *
 * @Author: 夏国倩
 * @Date: 2023/9/21 18:50
 * @Copyright
 */
package Set;
import java.util.ArrayList;
import java.util.List;
public class Test5 {
    public static void main(String[] args) {
        List<Student> list=new ArrayList<>();
        list.add(new Student("2000661","张三","男",35));
        list.add(new Student("2000662","李四","男",26));
        list.add(new Student("2000663","王五","女",16));
        list.add(new Student("2000664","李明","男",30));
        list.add(new Student("2000665","王浩","男",18));
        show(list);
        System.out.println(list); //输出所有学生信息
    }
    public static void show(List<Student> list){
        //判断名叫张三的学生是否存在于该集合中
        for (Student student:list){
            if (student.getName().equals("张三")){
                System.out.println("名叫张三的学生在该集合中");
                break;
            }
        }
        //统计年龄小于18岁的人数
        int count=0;
        for(Student student:list){
            if (student.getAge()<18){
                count++;
                System.out.println("小于18岁的人数有："+count+"个");
            }
        }
    }
}
class Student{
    private String StudentNumber;
    private String Name;
    private String sex;
    private int age;

    public String toString(){
        return "Student{"+"StudentNumber="+StudentNumber+'\''+",Name="+Name+'\''+",sex="+sex+",age="+age+"}";
    }

    public Student(String studentNumber, String name, String sex, int age) {
        StudentNumber = studentNumber;
        Name = name;
        this.sex = sex;
        this.age = age;
    }

    public String getStudentNumber() {
        return StudentNumber;
    }

    public void setStudentNumber(String studentNumber) {
        StudentNumber = studentNumber;
    }

    public String getName() {
        return Name;
    }

    public void setName(String name) {
        Name = name;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}

